package com.huatai.exchange.integration.execd.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.integration.http.HttpClientUtils;
import com.google.common.collect.Maps;
import com.huatai.exchange.integration.execd.AbstractExecdService;
import com.huatai.exchange.integration.execd.service.RequestFileService;
import org.springframework.stereotype.Service;

import java.io.OutputStream;

@Service
public class RequestFileServiceImpl extends AbstractExecdService implements RequestFileService {

    @Override
    public void requestFile(OutputStream os, String path) throws BusinessException {
        requestFile(os,path,"default") ;
    }

    @Override
    public void requestFile(OutputStream os, String path, String ipPath) throws BusinessException {
        try {
            String param = path.replace("/","-") ;
            String url = baseUrl + "requestfile/" + param;
            HttpClientUtils.downLoadFile(url, Maps.newHashMap(), os);
        } catch (Exception ex) {
            throw new BusinessException(ex.getMessage());
        }
    }
}
